package com.stox.shared.indicator.model.config;

import com.stox.shared.core.model.enumeration.BarValue;

public class BaseIndicatorConfig implements SpanAwareConfig, BarValueAwareConfig {

	private int span = 20;
	private BarValue barValue = BarValue.CLOSE;

	public BaseIndicatorConfig() {
		
	}
	
	public BaseIndicatorConfig(String text) {
		String[] tokens = text.split(",");
		span = Integer.parseInt(tokens[1]);
		barValue = BarValue.valueOf(tokens[0]);
	}
	
	@Override
	public String toString() {
		return barValue.name()+","+span;
	}
	
	/*public static void main(String[] args) throws IOException, ClassNotFoundException {
		BaseIndicatorConfig config = new BaseIndicatorConfig();
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		ObjectOutputStream oos = new ObjectOutputStream(baos);
		oos.writeObject(config);
		oos.close();
		String text = baos.toString();
		System.out.println(text);
		
		ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(text.getBytes()));
		System.out.println(ois.readObject());
	}*/
	
	@Override
	public int getSpan() {
		return span;
	}

	public void setSpan(final int span) {
		this.span = span;
	}

	@Override
	public BarValue getBarValue() {
		return barValue;
	}

	public void setBarValue(final BarValue barValue) {
		this.barValue = barValue;
	}

}
